﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AnaxibiaStudios.Smug;

namespace SmugTest
{
#if DETOUR_ENABLED
  [TestClass]
  public class SequencedTest
  {
    [TestMethod]
    public void BasicSequencedTest()
    {
      var cat = Create.Proxy<Cat>();

      Prepare.Action(cat.Meow);
      Prepare.Action(cat.Blink);

      cat.Meow();
      cat.Blink();

      Verify.AllCallsInOrderTo(cat);
    }

    [TestMethod]
    public void PredefinedBasicSequencedTest()
    {
      var cat = Create.Proxy<Cat>();

      Prepare.Action(cat.Meow, ReplayRule.InOrder);
      Prepare.Action(cat.Blink, ReplayRule.InOrder);

      cat.Meow();
      cat.Blink();

      Verify.AllCallsTo(cat);
    }

    [TestMethod]
    public void InOrderAndOutMixTest()
    {
      var cat = Create.Proxy<Cat>();

      var rule0 = Prepare.Call<int>(() => cat.Pet(0), ReplayRule.InOrder).Returns(10).CalledOnce();
      var rule1 = Prepare.Call<int>(() => cat.Pet(1)).Returns(11).CalledOnce();
      var rule2 = Prepare.Call<int>(() => cat.Pet(2), ReplayRule.InOrder).Returns(22).CalledOnce();
      var rule3 = Prepare.Call<int>(() => cat.Pet(3)).Returns(33).CalledOnce();
      var rule4 = Prepare.Call<int>(() => cat.Pet(4), ReplayRule.InOrder).Returns(44).CallCount(3);
      var rule5 = Prepare.Call<int>(() => cat.Pet(5)).Returns(55).CallCount(3);
      var rule6 = Prepare.Call<int>(() => cat.Pet(6), ReplayRule.InOrder).Returns(66);
      var rule7 = Prepare.Call<int>(() => cat.Pet(7)).Returns(77);
      var rule8 = Prepare.Call<int>(() => cat.Pet(8), ReplayRule.InOrder).Returns(88);

      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(10, cat.Pet(0));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(33, cat.Pet(3));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(55, cat.Pet(5));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(55, cat.Pet(5));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(55, cat.Pet(5));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(22, cat.Pet(2));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(44, cat.Pet(4));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(44, cat.Pet(4));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(44, cat.Pet(4));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(88, cat.Pet(8));
      Assert.AreEqual(77, cat.Pet(7));
      Assert.AreEqual(11, cat.Pet(1));

      Verify.AllCallsTo(cat, ReplayRule.PreparedMethodsOnly);
    }
  }
#endif
}
